/**
 * 修改相机的控制方式;
 * @param camera 通用相机;
 */
import {global} from 'Main';

export function modifyCameraControlMode(camera: BABYLON.UniversalCamera) {
    camera.keysUp.push(87);     //w
    camera.keysDown.push(83);   //s
    camera.keysLeft.push(65);   //a
    camera.keysRight.push(68);  //d

    //禁用相机上下移动
    camera.keysUpward = [];
    camera.keysDownward = [];
}

/**
 * 对指定mesh添加点击后进行指定场景切换和渲染的动作;
 */
export function pickToRender(mesh: BABYLON.AbstractMesh, renderScene: SCENE){
    var actionManager = mesh.actionManager = new BABYLON.ActionManager(mesh.getScene());
    actionManager.registerAction(
        new BABYLON.ExecuteCodeAction(
            BABYLON.ActionManager.OnPickTrigger, 
            () =>{
                global.askForRender(renderScene);
            },
            new BABYLON.PredicateCondition(actionManager, () => {
                console.log('render: '+renderScene);
                return true;
            })
        )
    );
}

/**
 * 使用gui2d对点击事件进行响应;
 */
export function clickToRender(mesh: BABYLON.AbstractMesh, renderScene: SCENE){
    var advancedTexture = BABYLON.GUI.AdvancedDynamicTexture.CreateForMesh(mesh);
    var text = new BABYLON.GUI.TextBlock();
    text.text = "click";
    text.onPointerClickObservable.add(function() {
        global.askForRender(renderScene);
    });
    advancedTexture.addControl(text);

}

// /**
//  * 使用gui3d对点击事件进行响应;
//  * @param mesh 要添加点击事件的3d物体
//  * @param renderScene 要切换的场景
//  */
// function clickToRender3D(mesh: BABYLON.Mesh, meshScene: SCENE, renderScene: SCENE){
//     var render = () => {
//         global.GUI3DManagers[global.sceneOnRender].utilityLayer.shouldRender = false;
//         global.askForRender(renderScene);
//     };
//     clickToDo(mesh, meshScene, false, render);
// }

// /**
//  * 
//  * @param mesh 
//  * @param meshScene 
//  * @param callBack 
//  */
// function clickToDo(mesh: BABYLON.Mesh, meshScene: SCENE, animation: boolean, callBack: ()=>void){
//     var btn3D = new BABYLON.GUI.MeshButton3D(mesh);
//     if(global.GUI3DManagers[meshScene] == null){
//         global.GUI3DManagers[meshScene] = new BABYLON.GUI.GUI3DManager(mesh.getScene());
//         global.GUI3DManagers[meshScene].utilityLayer.shouldRender = false;
//     }
//     global.GUI3DManagers[meshScene].addControl(btn3D);

//     if(!animation){   //禁用3d button的点击动画
//         btn3D.pointerEnterAnimation = ()=>{

//         };
//         btn3D.pointerOutAnimation = ()=>{
    
//         };
//         btn3D.pointerUpAnimation = ()=>{
    
//         };
//         btn3D.pointerDownAnimation = ()=>{
    
//         };
//     }

//     btn3D.onPointerClickObservable.add(callBack);
// }